<template>
  <div class="dashboard-container">
    <div class="dashboard-text" style="display:none;">当前登录用户: {{ name }}</div>
    <panelGroup @handleSetLineChartData="handleSetLineChartData" />
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <lineChart :chart-data="lineChartData" />
    </el-row>
  </div>
</template>

<script>
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
import { mapGetters } from 'vuex'
import { getDashboardListNumber } from '@/api/questionnaire'

export default {
  name: 'Dashboard',
  components: {
    PanelGroup,
    LineChart
  },
  data() {
    return {
      lineChartData: {},
      dataMap: {}
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  mounted: function() {
    getDashboardListNumber().then(res => {
      if (res.data) {
        this.dataMap = res.data
        this.lineChartData = res.data.login_times
      }
    })
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = this.dataMap[type]
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
